package com.weixiaodong.ModelDesign.适应设计模式.Iterator模式.练习;

import com.weixiaodong.ModelDesign.适应设计模式.Iterator模式.遍历书籍程序案例演示.Aggregate;
import com.weixiaodong.ModelDesign.适应设计模式.Iterator模式.遍历书籍程序案例演示.Book;
import com.weixiaodong.ModelDesign.适应设计模式.Iterator模式.遍历书籍程序案例演示.Iterator;

import java.util.ArrayList;

@SuppressWarnings("all")
public class BookShelf implements Aggregate {
    private ArrayList<Book> bookShelf;

    private int last;

    public BookShelf() {
        last = 0;
        bookShelf = new ArrayList<>();
    }

    public void appendBook(Book book) {
        this.bookShelf.add(book);
        last++;
    }

    public Book getBook(int index) {
        return this.bookShelf.get(index);
    }

    public int getSize() {
        return this.last;
    }

    @Override
    public Iterator iterator() {
        return new BookShelfIterator(this);
    }
}
